import Base from '@/views/Base'
import api from '@/server/api'
import moment from 'moment'
const { getArticles, delArticle } = api

export default class extends Base {
  getArticleList () {
    getArticles().then(res => {
      let list = res.result.list
      console.log(list)
      this.vm.tableBody = list.map(val => {
        let todayStart = new Date()
        todayStart.setHours(0, 0, 0, 0)
        let time = val.time * 1
        return {
          id: val.articleId,
          articleType: val.articleType,
          title: val.title,
          author: val.author,
          content: val.content,
          type: val.articleType,
          date: time > todayStart ? moment(time).format('HH:MM:SS') : moment(time).format('YYYY-MM-DD')
        }
      })
    })
  }
  delArticle (id) {
    if (!id) {
      this.vm.$Message.error('what\'s id ?')
    } else {
      delArticle(id).then(res => {
        if (res.status === 1) {
          this.vm.$Message.error(res.msg)
        } else {
          this.getArticleList()
          this.vm.$Message.success(res.msg)
        }
      })
    }
  }
}
